<template>
  <div class="container">
    <div class="input_box">
      <div class="input_list flex-row flex-y-center vux-1px-b">
        <input v-model="phone" type="text" placeholder="手机号/用户名/账号">
      </div>
      <div class="input_list flex-row flex-y-center vux-1px-b">
        <input v-model="password" placeholder="密码(6-12位)">
      </div>
    </div>
    <button @click="loginBtn" class="startBtn">登录</button>
    <div class="flex-row bottom-desc">
      <div class="flex-grow-1" @click="toregister">注册</div>
      <div class="flex-grow-1 flex-right" @click="toForgetPassWord">忘记密码?</div>
    </div>
  </div>
</template>

<script>
  import {LOGIN} from "src/const/uri";
  import axios from 'axios'

  export default {
    name: "Login",
    data() {
      return {
        phone: '',
        password: '',
        passwordreg: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/,
        phonereg: /^1([38]\d|5[0-35-9]|7[3678])\d{8}$/,
        formdata: new FormData(),
      }
    },
    methods: {
      loginBtn() {
        if (!this.phone) {
          this.$vux.toast.text('请输入手机号');
          return false
        } else if (!this.phonereg.test(this.phone)) {
          this.$vux.toast.text('请输入正确的手机号');
          return false
        } else if (!this.password) {
          this.$vux.toast.text('请输入密码');
          return false
        }
        let formdata = new FormData();
        formdata.append('phone', this.phone);
        formdata.append('password', this.password);
        this.$ajax.uploadForm(LOGIN, {}, formdata).then(res => {
          this.$vux.toast.text(res.msg)
          if(res.code===200){
            // console.log(res.data);
            window.localStorage.setItem('jcyy_uid',res.data.id);
            window.localStorage.setItem('jcyy_token',res.data.token)
          }

          // this.$vux.toast.text(res.msg)
          // if(res.code==0){
          //   this.$vux.toast.text(res.msg);
          // }else if(res.code==1){
          //   this.$vux.toast.text(res.msg);
          // }
        })
      },
      toregister() {
        let toUrl = window.location.origin + '/register.html';
        window.location.href = toUrl;
      },
      toForgetPassWord() {
        let toUrl = window.location.origin + '/forgetpassword.html';
        window.location.href = toUrl;
      }
    }
  }
</script>

<style scoped lang="less">
  .container {
    background: #fff;
  }

  .input_box {
    padding: 0.4rem 0.2rem 0.32rem;

    .input_list {
      background: #fff;
      font-size: 0.3rem;
      height: 0.91rem;
      margin-bottom: 0.18rem;
      padding-left: 0.3rem;

      label {
        width: 1.5rem;
      }

      input {
        width: 100%;
        font-size: 0.3rem;
        border: 0;
        background: #fff;
        height: 99%;
      }

      &.input_list_code {
        background: transparent;
        padding-left: 0;
        font-size: 0.3rem;

        .code {
          background: #fff;
          padding-left: 0.3rem;
          height: 100%;
          border-radius: 50px;

          input {
            width: 2rem;
          }
        }

        .code_btn {
          width: 2.49rem;
          height: .92rem;
          text-align: center;
          line-height: .92rem;
          background: #fff;
          margin-left: 0.17rem;
          border-radius: 50px;
          border: 0;

          &.active {
            color: red;
          }
        }
      }
    }
  }

  .startBtn {
    display: block;
    width: 7.11rem;
    height: .91rem;
    background: red;
    color: #fff;
    font-size: .3rem;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    margin: 0.3rem auto 0;
  }

  .bottom-desc {
    width: 7.11rem;
    margin: 0.2rem auto;
    font-size: 16px;
  }
</style>
